// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "AbilitySystemInterface.h"
#include "GameFramework/PlayerState.h"
#include "AuraPlayerState.generated.h"

class ULevelUpInfo;
struct FGameplayAttributeData;
class UAbilitySystemComponent;
class UAttributeSet;

DECLARE_MULTICAST_DELEGATE_OneParam(FOnPlayerStateChangedSignature, int32);

/**
 * 自定义玩家状态类
 */
UCLASS()
class AURA_API AAuraPlayerState : public APlayerState, public IAbilitySystemInterface
{
	GENERATED_BODY()

public:

	AAuraPlayerState();

	virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;

	FORCEINLINE int32 GetCharacterLevel() const { return Level; } // 获取等级
	void AddToLevel(int32 InLevel); // 增加等级
	void SetLevel(int32 InLevel); // 设置当前等级

	FORCEINLINE int32 GetXP() const { return XP; } // 获取经验值
	void AddToXP(int32 InXP); // 增加经验值
	void SetXP(int32 InXP); // 设置当前经验值

	FOnPlayerStateChangedSignature OnXPChangedDelegate; //经验值变动委托
	FOnPlayerStateChangedSignature OnLevelChangedDelegate; //等级变动委托

	/** 角色升级相关数据 */
	UPROPERTY(EditDefaultsOnly)
	TObjectPtr<ULevelUpInfo> LevelUpInfo = nullptr;

	UAttributeSet* GetAttributeSet() const;

	// ----------------------------------------------------------------------------------------------------------------
	//	IAbilitySystemInterface接口
	// ----------------------------------------------------------------------------------------------------------------
	virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;

protected:

	UPROPERTY()
	TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent;

	UPROPERTY()
	TObjectPtr<UAttributeSet> AttributeSet;

	// ----------------------------------------------------------------------------------------------------------------
	//	玩家等级
	// ----------------------------------------------------------------------------------------------------------------

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, ReplicatedUsing= "OnRep_Level")
	int32 Level;

	UFUNCTION()
	void OnRep_Level(int OldLevel);

	// ----------------------------------------------------------------------------------------------------------------
	//	玩家经验值
	// ----------------------------------------------------------------------------------------------------------------

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, ReplicatedUsing= "OnRep_XP")
	int32 XP;

	UFUNCTION()
	void OnRep_XP(int OldXP);
};
